package gao.xiaolei.controller;

import org.springframework.web.bind.annotation.*;
import gao.xiaolei.util.RedisUtil;

import javax.annotation.Resource;

@RestController
@RequestMapping("/cache")
public class CacheController {

    @Resource(name = "RedisUtil")
    private RedisUtil redisUtil;

    @GetMapping("/inProject/{userId}")
    public String getInProject(@PathVariable("userId") String userId) {
        return (String) redisUtil.get(userId);
    }

    @PutMapping("/inProject")
    public void refreshInProject(@RequestParam("userId") String userId,
                                 @RequestParam("projectId") String projectId) {
        redisUtil.set(userId, projectId);//更新用户选择的project
    }

    @DeleteMapping("/inProject/{userId}")
    public void deleteInProject(@PathVariable("userId") String userId) {
        redisUtil.del(userId);//用于注销的时候删除缓存
    }
}
